<?php // oo_stats.php -- shows printer out-of-order stats

// Include important constants and set admin_home (we need to set the variable since file() doesn't interpret constants in pathnames)

require_once("../init.php");
$admin_home = ADMIN_HOME;

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
	<title>Out-of-Order data</title>
	<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
	
	<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
	<meta name="author" content="Dylan J. Sather" />
	<meta name="revised" content= <?php

	/* This script checks the date_modified file to give the date at which a file on the 
	   map was last modified, thus giving us the date at which the map was last revised */

	$date_file = "$admin_home/map_files/oo_stats_date_modified";
	$fh = fopen($date_file, 'r');
	$date = fread($fh, filesize($date_file));
	$date = trim($date);
	fclose($fh);
	print "\"Dylan J. Sather, $date\" />";

	?>

	<meta name="description" content="Grinnell College Campus Lab Map" />
	<meta name="keywords"
		content="Grinnell College, TC Corps, Technology Consultant,
			Computer lab, Map, Dylan J. Sather" />
	<meta http-equiv="Content-Style-Type" content="text/css" />
	<meta http-equiv="Content-Script-Type" content="text/javascript" />
	<link rel="stylesheet" type="text/css" href="../css/labmap.css" />
      </head>	   

<body>

<div class="wrapper"> <!-- WRAPPER div -->

	<div class="floatleft"> <!-- LEFT div -->

		<?php // Show historical out-of-order data

		// "Scan" directory
		
		$oo_stats_dir = "$admin_home/printers/oo_status/old_stats";
		$files = scandir ($oo_stats_dir);

		print '<h2 class="centeralign">Historical Out-of-Order statistics, filed by year</h2>
		<p class="centeralign">';

		// Now here's the cool part -- for each date, print a link to the file corresponding to that date

		foreach ($files as $_ => $oo_stat_year) {
			
			// If we've got a virtual directory, don't list it
			if ($oo_stat_year == '.' || $oo_stat_year == '..') {
				// Do nothing
			}
			else {
				print "<a href=\"http://tcdb.grinnell.edu/map/oo_stats/archives.php?year=$oo_stat_year\">$oo_stat_year</a><br />\n";
			}
		}				

		print "</p>\n";
		
		print "</div> <!-- End LEFT div -->
		<div class=\"floatright\"> <!-- RIGHT div -->\n
		<h2 class=\"centeralign\">Today's Out-of-Order statistics</h2>";

		$oo_file = "$admin_home/printers/oo_status/oo_stats";
		$fh2 = fopen($oo_file, 'r');
		if (filesize($oo_file) == 0) {
			fclose($fh2);
		}

		else {
			$data = fread($fh2, filesize($oo_file));
			fclose($fh2);

			print "<pre class=\"centeralign\">$data</pre>\n";
		}

?>

	</div> <!-- End RIGHT div -->

</div> <!-- End WRAPPER div -->

</body>

</html>

